home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / STRINGLib.lha / STRINGLib / Developer / source / TestVBCC.c < prev   
Encoding:
C/C++ Source or Header  |  1999-08-08  |  20.3 KB  |  656 lines

  1. /*** excluded for vbcc, see below
  2. *MP* _cli_parse(){return;}
  3. *MP* _wb_parse(){return;}
  4. ***/
  5.  
  6. /*
  7.  * Test program for string(3) routines.
  8.  * 
  9.  * Note that at least one Bell Labs implementation of the string
  10.  * routines flunks a couple of these tests -- the ones which test
  11.  * behavior on "negative" characters.
  12.  */
  13.  
  14. /* 11.12.1998 Michaela Prüß, i make a vbcc-version of the test
  15.  * will you know what happend? compile and lock...!
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include "TestVBCC_protos.h"
  21.  
  22. #define NUL 0
  23. #define    STREQ(a, b)    (strcmp((a), (b)) == 0)
  24.  
  25. char *it = "<UNSET>";        /* Routine name for message routines. */
  26. int waserror = 0;        /* For exit status. */
  27.  
  28. char uctest[] = "\004\203";    /* For testing signedness of chars. */
  29. int charsigned;            /* Result. */
  30.  
  31. /*
  32.  - check - complain if condition is not true
  33.  -
  34. *MP* no return also uses void, not int
  35. *MP* int number must printed with %d, not %ld
  36.  -
  37.  */
  38.  
  39. void check(int thing, int number)            /* Test number for error message. */
  40. {
  41.     if (!thing) {
  42.         printf("%s flunked test %d\n", it, number);
  43.         waserror = 1;
  44.     }
  45. }
  46.  
  47. /*
  48.  - equal - complain if first two args don't strcmp as equal
  49.  -
  50. *MP* no return also uses void, not int
  51.  -
  52.  */
  53.  
  54. void equal(char *a, char *b, int number)            /* Test number for error message. */
  55. {
  56.     check(a != NULL && b != NULL && STREQ(a, b), number);
  57. }
  58.  
  59. char one[50];
  60. char two[50];
  61.  
  62. #ifdef UNIXERR
  63. #define ERR 1
  64. #endif
  65. #ifdef BERKERR
  66. #define ERR 1
  67. #endif
  68. #ifdef ERR
  69. int f;
  70. #ifdef unix
  71. extern char *sys_errlist[];
  72. extern int sys_nerr;
  73. #else
  74. char *sys_errlist[1] = {"dummy entry to keep compilers happy"};
  75. int sys_nerr = 1;
  76. #endif
  77. extern int errno;
  78. #endif
  79.  
  80. /* ARGSUSED
  81.  -
  82. *MP* prototyp without any returntype, added int
  83.  -
  84.  */
  85.  
  86. int main(int argc, char *argv[])
  87. {
  88.     /*
  89.      * First, establish whether chars are signed.
  90.      */
  91.     if (uctest[0] < uctest[1])
  92.         charsigned = 0;
  93.     else
  94.         charsigned = 1;
  95.  
  96.     /*
  97.      * Then, do the rest of the work.  Split into two functions because
  98.      * some compilers get unhappy about a single immense function.
  99.      */
  100.     first();
  101.     second();
  102.  
  103.     exit((waserror) ? 1 : 0);
  104. }
  105.  
  106. /*MP* added void */
  107.  
  108. void first()
  109. {
  110.     /*
  111.      * Test strcmp first because we use it to test other things.
  112.      */
  113.     it = "strcmp";
  114.     check(strcmp("", "") == 0, 1);        /* Trivial case. */
  115.     check(strcmp("a", "a") == 0, 2);    /* Identity. */
  116.     check(strcmp("abc", "abc") == 0, 3);    /* Multicharacter. */
  117.     check(strcmp("abc", "abcd") < 0, 4);    /* Length mismatches. */
  118.     check(strcmp("abcd", "abc") > 0, 5);
  119.     check(strcmp("abcd", "abce") < 0, 6);    /* Honest miscompares. */
  120.     check(strcmp("abce", "abcd") > 0, 7);
  121.     check(strcmp("a\203", "a") > 0, 8);    /* Tricky if char signed. */
  122.     if (charsigned)                /* Sign-bit comparison. */
  123.         check(strcmp("a\203", "a\003") < 0, 9);
  124.     else
  125.         check(strcmp("a\203", "a\003") > 0, 9);
  126.  
  127.     /*
  128.      * Test strcpy next because we need it to set up other tests.
  129.      */
  130.     it = "strcpy";
  131.     check(strcpy(one, "abcd") == one, 1);    /* Returned value. */
  132.     equal(one, "abcd", 2);            /* Basic test. */
  133.  
  134.     /*int*/ strcpy(one, "x");
  135.     equal(one, "x", 3);            /* Writeover. */
  136.     equal(one+2, "cd", 4);            /* Wrote too much? */
  137.  
  138.     /*void*/ strcpy(two, "hi there");
  139.     /*void*/ strcpy(one, two);
  140.     equal(one, "hi there", 5);        /* Basic test encore. */
  141.     equal(two, "hi there", 6);        /* Stomped on source? */
  142.  
  143.     /*void*/ strcpy(one, "");
  144.     equal(one, "", 7);            /* Boundary condition. */
  145.  
  146.     /*
  147.      * strcat
  148.      */
  149.     it = "strcat";
  150.     /*void*/ strcpy(one, "ijk");
  151.     check(strcat(one, "lmn") == one, 1);    /* Returned value. */
  152.     equal(one, "ijklmn", 2);        /* Basic test. */
  153.  
  154.     /*void*/ strcpy(one, "x");
  155.     /*void*/ strcat(one, "yz");
  156.     equal(one, "xyz", 3);            /* Writeover. */
  157.     equal(one+4, "mn", 4);            /* Wrote too much? */
  158.  
  159.     /*void*/ strcpy(one, "gh");
  160.     /*void*/ strcpy(two, "ef");
  161.     /*void*/ strcat(one, two);
  162.     equal(one, "ghef", 5);            /* Basic test encore. */
  163.     equal(two, "ef", 6);            /* Stomped on source? */
  164.  
  165.     /*void*/ strcpy(one, "");
  166.     /*void*/ strcat(one, "");
  167.     equal(one, "", 7);            /* Boundary conditions. */
  168.     /*void*/ strcpy(one, "ab");
  169.     /*void*/ strcat(one, "");
  170.     equal(one, "ab", 8);
  171.     /*void*/ strcpy(one, "");
  172.     /*void*/ strcat(one, "cd");
  173.     equal(one, "cd", 9);
  174.  
  175.     /*
  176.      * strncat - first test it as strcat, with big counts, then
  177.      * test the count mechanism.
  178.      */
  179.     it = "strncat";
  180.     /*void*/ strcpy(one, "ijk");
  181.     check(strncat(one, "lmn", 99) == one, 1);    /* Returned value. */
  182.     equal(one, "ijklmn", 2);        /* Basic test. */
  183.  
  184.     /*void*/ strcpy(one, "x");
  185.     /*void*/ strncat(one, "yz", 99);
  186.     equal(one, "xyz", 3);            /* Writeover. */
  187.     equal(one+4, "mn", 4);            /* Wrote too much? */
  188.  
  189.     /*void*/ strcpy(one, "gh");
  190.     /*void*/ strcpy(two, "ef");
  191.     /*void*/ strncat(one, two, 99);
  192.     equal(one, "ghef", 5);            /* Basic test encore. */
  193.     equal(two, "ef", 6);            /* Stomped on source? */
  194.  
  195.     /*void*/ strcpy(one, "");
  196.     /*void*/ strncat(one, "", 99);
  197.     equal(one, "", 7);            /* Boundary conditions. */
  198.     /*void*/ strcpy(one, "ab");
  199.     /*void*/ strncat(one, "", 99);
  200.     equal(one, "ab", 8);
  201.     /*void*/ strcpy(one, "");
  202.     /*void*/ strncat(one, "cd", 99);
  203.     equal(one, "cd", 9);
  204.  
  205.     /*void*/ strcpy(one, "ab");
  206.     /*void*/ strncat(one, "cdef", 2);
  207.     equal(one, "abcd", 10);            /* Count-limited. */
  208.  
  209.     /*void*/ strncat(one, "gh", 0);
  210.     equal(one, "abcd", 11);            /* Zero count. */
  211.  
  212.     /*void*/ strncat(one, "gh", 2);
  213.     equal(one, "abcdgh", 12);        /* Count and length equal. */
  214.  
  215.     /*
  216.      * strncmp - first test as strcmp with big counts, then test
  217.      * count code.
  218.      */
  219.     it = "strncmp";
  220.     check(strncmp("", "", 99) == 0, 1);    /* Trivial case. */
  221.     check(strncmp("a", "a", 99) == 0, 2);    /* Identity. */
  222.     check(strncmp("abc", "abc", 99) == 0, 3);    /* Multicharacter. */
  223.     check(strncmp("abc", "abcd", 99) < 0, 4);    /* Length unequal. */
  224.     check(strncmp("abcd", "abc", 99) > 0, 5);
  225.     check(strncmp("abcd", "abce", 99) < 0, 6);    /* Honestly unequal. */
  226.     check(strncmp("abce", "abcd", 99) > 0, 7);
  227.     check(strncmp("a\203", "a", 2) > 0, 8);    /* Tricky if '\203' < 0 */
  228.     if (charsigned)                /* Sign-bit comparison. */
  229.         check(strncmp("a\203", "a\003", 2) < 0, 9);
  230.     else
  231.         check(strncmp("a\203", "a\003", 2) > 0, 9);
  232.     check(strncmp("abce", "abcd", 3) == 0, 10);    /* Count limited. */
  233.     check(strncmp("abce", "abc", 3) == 0, 11);    /* Count == length. */
  234.     check(strncmp("abcd", "abce", 4) < 0, 12);    /* Nudging limit. */
  235.     check(strncmp("abc", "def", 0) == 0, 13);    /* Zero count. */
  236.  
  237.     /*
  238.      * strncpy - testing is a bit different because of odd semantics
  239.      */
  240.     it = "strncpy";
  241.     check(strncpy(one, "abc", 4) == one, 1);    /* Returned value. */
  242.     equal(one, "abc", 2);            /* Did the copy go right? */
  243.  
  244.     /*void*/ strcpy(one, "abcdefgh");
  245.     /*void*/ strncpy(one, "xyz", 2);
  246.     equal(one, "xycdefgh", 3);        /* Copy cut by count. */
  247.  
  248.     /*void*/ strcpy(one, "abcdefgh");
  249.     /*void*/ strncpy(one, "xyz", 3);        /* Copy cut just before NUL. */
  250.     equal(one, "xyzdefgh", 4);
  251.  
  252.     /*void*/ strcpy(one, "abcdefgh");
  253.     /*void*/ strncpy(one, "xyz", 4);        /* Copy just includes NUL. */
  254.     equal(one, "xyz", 5);
  255.     equal(one+4, "efgh", 6);        /* Wrote too much? */
  256.  
  257.     /*void*/ strcpy(one, "abcdefgh");
  258.     /*void*/ strncpy(one, "xyz", 5);        /* Copy includes padding. */
  259.     equal(one, "xyz", 7);
  260.     equal(one+4, "", 8);
  261.     equal(one+5, "fgh", 9);
  262.  
  263.     /*void*/ strcpy(one, "abc");
  264.     /*void*/ strncpy(one, "xyz", 0);        /* Zero-length copy. */
  265.     equal(one, "abc", 10);    
  266.  
  267.     /*void*/ strncpy(one, "", 2);        /* Zero-length source. */
  268.     equal(one, "", 11);
  269.     equal(one+1, "", 12);    
  270.     equal(one+2, "c", 13);
  271.  
  272.     /*void*/ strcpy(one, "hi there");
  273.     /*void*/ strncpy(two, one, 9);
  274.     equal(two, "hi there", 14);        /* Just paranoia. */
  275.     equal(one, "hi there", 15);        /* Stomped on source? */
  276.  
  277.     /*
  278.      * strlen
  279.      */
  280.     it = "strlen";
  281.     check(strlen("") == 0, 1);        /* Empty. */
  282.     check(strlen("a") == 1, 2);        /* Single char. */
  283.     check(strlen("abcd") == 4, 3);        /* Multiple chars. */
  284.  
  285.     /*
  286.      * strchr
  287.      */
  288.     it = "strchr";
  289.     check(strchr("abcd", 'z') == NULL, 1);    /* Not found. */
  290.     /*void*/ strcpy(one, "abcd");
  291.     check(strchr(one, 'c') == one+2, 2);    /* Basic test. */
  292.     check(strchr(one, 'd') == one+3, 3);    /* End of string. */
  293.     check(strchr(one, 'a') == one, 4);    /* Beginning. */
  294.     check(strchr(one, '\0') == one+4, 5);    /* Finding NUL. */
  295.     /*void*/ strcpy(one, "ababa");
  296.     check(strchr(one, 'b') == one+1, 6);    /* Finding first. */
  297.     /*void*/ strcpy(one, "");
  298.     check(strchr(one, 'b') == NULL, 7);    /* Empty string. */
  299.     check(strchr(one, '\0') == one, 8);    /* NUL in empty string. */
  300.  
  301.     /*
  302.      * index - just like strchr
  303.      */
  304. //    it = "index";
  305. //    check(index("abcd", 'z') == NULL, 1);    /* Not found. */
  306. //    /*void*/ strcpy(one, "abcd");
  307. //    check(index(one, 'c') == one+2, 2);    /* Basic test. */
  308. //    check(index(one, 'd') == one+3, 3);    /* End of string. */
  309. //    check(index(one, 'a') == one, 4);    /* Beginning. */
  310. //    check(index(one, '\0') == one+4, 5);    /* Finding NUL. */
  311. //    /*void*/ strcpy(one, "ababa");
  312. //    check(index(one, 'b') == one+1, 6);    /* Finding first. */
  313. //    /*void*/ strcpy(one, "");
  314. //    check(index(one, 'b') == NULL, 7);    /* Empty string. */
  315. //    check(index(one, '\0') == one, 8);    /* NUL in empty string. */
  316.  
  317.     printf("test 'index' skipped, because not exists in vbcc\n");
  318.  
  319.     /*
  320.      * strrchr
  321.      */
  322.     it = "strrchr";
  323.     check(strrchr("abcd", 'z') == NULL, 1);    /* Not found. */
  324.     /*void*/ strcpy(one, "abcd");
  325.     check(strrchr(one, 'c') == one+2, 2);    /* Basic test. */
  326.     check(strrchr(one, 'd') == one+3, 3);    /* End of string. */
  327.     check(strrchr(one, 'a') == one, 4);    /* Beginning. */
  328.     check(strrchr(one, '\0') == one+4, 5);    /* Finding NUL. */
  329.     /*void*/ strcpy(one, "ababa");
  330.     check(strrchr(one, 'b') == one+3, 6);    /* Finding last. */
  331.     /*void*/ strcpy(one, "");
  332.     check(strrchr(one, 'b') == NULL, 7);    /* Empty string. */
  333.     check(strrchr(one, '\0') == one, 8);    /* NUL in empty string. */
  334.  
  335.     /*
  336.      * rindex - just like strrchr
  337.      */
  338. //    it = "rindex";
  339. //    check(rindex("abcd", 'z') == NULL, 1);    /* Not found. */
  340. //    /*void*/ strcpy(one, "abcd");
  341. //    check(rindex(one, 'c') == one+2, 2);    /* Basic test. */
  342. //    check(rindex(one, 'd') == one+3, 3);    /* End of string. */
  343. //    check(rindex(one, 'a') == one, 4);    /* Beginning. */
  344. //    check(rindex(one, '\0') == one+4, 5);    /* Finding NUL. */
  345. //    /*void*/ strcpy(one, "ababa");
  346. //    check(rindex(one, 'b') == one+3, 6);    /* Finding last. */
  347. //    /*void*/ strcpy(one, "");
  348. //    check(rindex(one, 'b') == NULL, 7);    /* Empty string. */
  349. //    check(rindex(one, '\0') == one, 8);    /* NUL in empty string. */
  350.  
  351.     printf("test 'rindex' skipped, because not exists in vbcc\n");
  352. }
  353.  
  354. /*MP* added void */
  355.  
  356. void second()
  357. {
  358.     /*
  359.      * strpbrk - somewhat like strchr
  360.      */
  361.     it = "strpbrk";
  362.     check(strpbrk("abcd", "z") == NULL, 1);    /* Not found. */
  363.     /*void*/ strcpy(one, "abcd");
  364.     check(strpbrk(one, "c") == one+2, 2);    /* Basic test. */
  365.     check(strpbrk(one, "d") == one+3, 3);    /* End of string. */
  366.     check(strpbrk(one, "a") == one, 4);    /* Beginning. */
  367.     check(strpbrk(one, "") == NULL, 5);    /* Empty search list. */
  368.     check(strpbrk(one, "cb") == one+1, 6);    /* Multiple search. */
  369.     /*void*/ strcpy(one, "abcabdea");
  370.     check(strpbrk(one, "b") == one+1, 7);    /* Finding first. */
  371.     check(strpbrk(one, "cb") == one+1, 8);    /* With multiple search. */
  372.     check(strpbrk(one, "db") == one+1, 9);    /* Another variant. */
  373.     /*void*/ strcpy(one, "");
  374.     check(strpbrk(one, "bc") == NULL, 10);    /* Empty string. */
  375.     check(strpbrk(one, "") == NULL, 11);    /* Both strings empty. */
  376.  
  377.     /*
  378.      * strstr - somewhat like strchr
  379.      */
  380.     it = "strstr";
  381.     check(strstr("abcd", "z") == NULL, 1);    /* Not found. */
  382.     check(strstr("abcd", "abx") == NULL, 2);    /* Dead end. */
  383.     /*void*/ strcpy(one, "abcd");
  384.     check(strstr(one, "c") == one+2, 3);    /* Basic test. */
  385.     check(strstr(one, "bc") == one+1, 4);    /* Multichar. */
  386.     check(strstr(one, "d") == one+3, 5);    /* End of string. */
  387.     check(strstr(one, "cd") == one+2, 6);    /* Tail of string. */
  388.     check(strstr(one, "abc") == one, 7);    /* Beginning. */
  389.     check(strstr(one, "abcd") == one, 8);    /* Exact match. */
  390.     check(strstr(one, "abcde") == NULL, 9);    /* Too long. */
  391.     check(strstr(one, "de") == NULL, 10);    /* Past end. */
  392.     check(strstr(one, "") == one+4, 11);    /* Finding empty. */
  393.     /*void*/ strcpy(one, "ababa");
  394.     check(strstr(one, "ba") == one+1, 12);    /* Finding first. */
  395.     /*void*/ strcpy(one, "");
  396.     check(strstr(one, "b") == NULL, 13);    /* Empty string. */
  397.     check(strstr(one, "") == one, 14);    /* Empty in empty string. */
  398.     /*void*/ strcpy(one, "bcbca");
  399.     check(strstr(one, "bca") == one+2, 15);    /* False start. */
  400.     /*void*/ strcpy(one, "bbbcabbca");
  401.     check(strstr(one, "bbca") == one+1, 16);    /* With overlap. */
  402.  
  403.     /*
  404.      * strspn
  405.      */
  406.     it = "strspn";
  407.     check(strspn("abcba", "abc") == 5, 1);    /* Whole string. */
  408.     check(strspn("abcba", "ab") == 2, 2);    /* Partial. */
  409.     check(strspn("abc", "qx") == 0, 3);    /* None. */
  410.     check(strspn("", "ab") == 0, 4);    /* Null string. */
  411.     check(strspn("abc", "") == 0, 5);    /* Null search list. */
  412.  
  413.     /*
  414.      * strcspn
  415.      */
  416.     it = "strcspn";
  417.     check(strcspn("abcba", "qx") == 5, 1);    /* Whole string. */
  418.     check(strcspn("abcba", "cx") == 2, 2);    /* Partial. */
  419.     check(strcspn("abc", "abc") == 0, 3);    /* None. */
  420.     check(strcspn("", "ab") == 0, 4);    /* Null string. */
  421.     check(strcspn("abc", "") == 3, 5);    /* Null search list. */
  422.  
  423.     /*
  424.      * strtok - the hard one
  425.      */
  426.     it = "strtok";
  427.     /*void*/ strcpy(one, "first, second, third");
  428.     equal(strtok(one, ", "), "first", 1);    /* Basic test. */
  429.     equal(one, "first", 2);
  430.     equal(strtok((char *)NULL, ", "), "second", 3);
  431.     equal(strtok((char *)NULL, ", "), "third", 4);
  432.     check(strtok((char *)NULL, ", ") == NULL, 5);
  433.     /*void*/ strcpy(one, ", first, ");
  434.     equal(strtok(one, ", "), "first", 6);    /* Extra delims, 1 tok. */
  435.     check(strtok((char *)NULL, ", ") == NULL, 7);
  436.     /*void*/ strcpy(one, "1a, 1b; 2a, 2b");
  437.     equal(strtok(one, ", "), "1a", 8);    /* Changing delim lists. */
  438.     equal(strtok((char *)NULL, "; "), "1b", 9);
  439.     equal(strtok((char *)NULL, ", "), "2a", 10);
  440.     /*void*/ strcpy(two, "x-y");
  441.     equal(strtok(two, "-"), "x", 11);    /* New string before done. */
  442.     equal(strtok((char *)NULL, "-"), "y", 12);
  443.     check(strtok((char *)NULL, "-") == NULL, 13);
  444.     /*void*/ strcpy(one, "a,b, c,, ,d");
  445.     equal(strtok(one, ", "), "a", 14);    /* Different separators. */
  446.     equal(strtok((char *)NULL, ", "), "b", 15);
  447.     equal(strtok((char *)NULL, " ,"), "c", 16);    /* Permute list too. */
  448.     equal(strtok((char *)NULL, " ,"), "d", 17);
  449.     check(strtok((char *)NULL, ", ") == NULL, 18);
  450.     check(strtok((char *)NULL, ", ") == NULL, 19);    /* Persistence. */
  451.     /*void*/ strcpy(one, ", ");
  452.     check(strtok(one, ", ") == NULL, 20);    /* No tokens. */
  453.     /*void*/ strcpy(one, "");
  454.     check(strtok(one, ", ") == NULL, 21);    /* Empty string. */
  455.     /*void*/ strcpy(one, "abc");
  456.     equal(strtok(one, ", "), "abc", 22);    /* No delimiters. */
  457.     check(strtok((char *)NULL, ", ") == NULL, 23);
  458.     /*void*/ strcpy(one, "abc");
  459.     equal(strtok(one, ""), "abc", 24);    /* Empty delimiter list. */
  460.     check(strtok((char *)NULL, "") == NULL, 25);
  461.     /*void*/ strcpy(one, "abcdefgh");
  462.     /*void*/ strcpy(one, "a,b,c");
  463.     equal(strtok(one, ","), "a", 26);    /* Basics again... */
  464.     equal(strtok((char *)NULL, ","), "b", 27);
  465.     equal(strtok((char *)NULL, ","), "c", 28);
  466.     check(strtok((char *)NULL, ",") == NULL, 29);
  467.     equal(one+6, "gh", 30);            /* Stomped past end? */
  468.     equal(one, "a", 31);            /* Stomped old tokens? */
  469.     equal(one+2, "b", 32);
  470.     equal(one+4, "c", 33);
  471.  
  472.     /*
  473.      * memcmp
  474.      */
  475.     it = "memcmp";
  476.     check(memcmp("a", "a", 1) == 0, 1);    /* Identity. */
  477.     check(memcmp("abc", "abc", 3) == 0, 2);    /* Multicharacter. */
  478.     check(memcmp("abcd", "abce", 4) < 0, 3);    /* Honestly unequal. */
  479.     check(memcmp("abce", "abcd", 4) > 0, 4);
  480.     check(memcmp("alph", "beta", 4) < 0, 5);
  481.     if (charsigned)                /* Sign-bit comparison. */
  482.         check(memcmp("a\203", "a\003", 2) < 0, 6);
  483.     else
  484.         check(memcmp("a\203", "a\003", 2) > 0, 6);
  485.     check(memcmp("abce", "abcd", 3) == 0, 7);    /* Count limited. */
  486.     check(memcmp("abc", "def", 0) == 0, 8);    /* Zero count. */
  487.  
  488.     /*
  489.      * memchr
  490.      */
  491.     it = "memchr";
  492.     check(memchr("abcd", 'z', 4) == NULL, 1);    /* Not found. */
  493.     /*void*/ strcpy(one, "abcd");
  494.     check(memchr(one, 'c', 4) == one+2, 2);    /* Basic test. */
  495.     check(memchr(one, 'd', 4) == one+3, 3);    /* End of string. */
  496.     check(memchr(one, 'a', 4) == one, 4);    /* Beginning. */
  497.     check(memchr(one, '\0', 5) == one+4, 5);    /* Finding NUL. */
  498.     /*void*/ strcpy(one, "ababa");
  499.     check(memchr(one, 'b', 5) == one+1, 6);    /* Finding first. */
  500.     check(memchr(one, 'b', 0) == NULL, 7);    /* Zero count. */
  501.     check(memchr(one, 'a', 1) == one, 8);    /* Singleton case. */
  502.     /*void*/ strcpy(one, "a\203b");
  503.     check(memchr(one, (char)0203, 3) == one+1, 9);    /* Unsignedness. */
  504.  
  505.     /*
  506.      * memcpy
  507.      *
  508.      * Note that X3J11 says memcpy must work regardless of overlap.
  509.      * The SVID says it might fail.
  510.      */
  511.     it = "memcpy";
  512.     check(memcpy(one, "abc", 4) == one, 1);    /* Returned value. */
  513.     equal(one, "abc", 2);            /* Did the copy go right? */
  514.  
  515.     /*void*/ strcpy(one, "abcdefgh");
  516.     /*void*/ memcpy(one+1, "xyz", 2);
  517.     equal(one, "axydefgh", 3);        /* Basic test. */
  518.  
  519.     /*void*/ strcpy(one, "abc");
  520.     /*void*/ memcpy(one, "xyz", 0);
  521.     equal(one, "abc", 4);            /* Zero-length copy. */
  522.  
  523.     /*void*/ strcpy(one, "hi there");
  524.     /*void*/ strcpy(two, "foo");
  525.     /*void*/ memcpy(two, one, 9);
  526.     equal(two, "hi there", 5);        /* Just paranoia. */
  527.     equal(one, "hi there", 6);        /* Stomped on source? */
  528.  
  529.     /*void*/ strcpy(one, "abcdefgh");
  530.     /*void*/ memcpy(one+1, one, 9);
  531.     equal(one, "aabcdefgh", 7);        /* Overlap, right-to-left. */
  532.  
  533.     /*void*/ strcpy(one, "abcdefgh");
  534.     /*void*/ memcpy(one+1, one+2, 7);
  535.     equal(one, "acdefgh", 8);        /* Overlap, left-to-right. */
  536.  
  537.     /*void*/ strcpy(one, "abcdefgh");
  538.     /*void*/ memcpy(one, one, 9);
  539.     equal(one, "abcdefgh", 9);        /* 100% overlap. */
  540.  
  541.     /*
  542.      * memccpy - first test like memcpy, then the search part
  543.      *
  544.      * The SVID, the only place where memccpy is mentioned, says
  545.      * overlap might fail, so we don't try it.  Besides, it's hard
  546.      * to see the rationale for a non-left-to-right memccpy.
  547.      */
  548. //    it =(char *)"memccpy";
  549. //    check(memccpy(one, "abc", 'q', 4) == NULL, 1);    /* Returned value. */
  550. //    equal(one, "abc", 2);            /* Did the copy go right? */
  551.  
  552. //    /*void*/ strcpy(one, "abcdefgh");
  553. //    /*void*/ memccpy(one+1, "xyz", 'q', 2);
  554. //    equal(one, "axydefgh", 3);        /* Basic test. */
  555.  
  556. //    /*void*/ strcpy(one, "abc");
  557. //    /*void*/ memccpy(one, "xyz", 'q', 0);
  558. //    equal(one, "abc", 4);            /* Zero-length copy. */
  559.  
  560. //    /*void*/ strcpy(one, "hi there");
  561. //    /*void*/ strcpy(two, "foo");
  562. //    /*void*/ memccpy(two, one, 'q', 9);
  563. //    equal(two, "hi there", 5);        /* Just paranoia. */
  564. //    equal(one, "hi there", 6);        /* Stomped on source? */
  565.  
  566. //    /*void*/ strcpy(one, "abcdefgh");
  567. //    /*void*/ strcpy(two, "horsefeathers");
  568. //    check(memccpy(two, one, 'f', 9) == two+6, 7);    /* Returned value. */
  569. //    equal(one, "abcdefgh", 8);        /* Source intact? */
  570. //    equal(two, "abcdefeathers", 9);        /* Copy correct? */
  571.  
  572. //    /*void*/ strcpy(one, "abcd");
  573. //    /*void*/ strcpy(two, "bumblebee");
  574. //    check(memccpy(two, one, 'a', 4) == two+1, 10);    /* First char. */
  575. //    equal(two, "aumblebee", 11);
  576. //    check(memccpy(two, one, 'd', 4) == two+4, 12);    /* Last char. */
  577. //    equal(two, "abcdlebee", 13);
  578. //    /*void*/ strcpy(one, "xyz");
  579. //    check(memccpy(two, one, 'x', 1) == two+1, 14);    /* Singleton. */
  580. //    equal(two, "xbcdlebee", 15);
  581.  
  582.     printf("test 'memccpy' skipped, because not exists in vbcc\n");
  583.  
  584.     /*
  585.      * memset
  586.      */
  587.     it = "memset";
  588.     /*void*/ strcpy(one, "abcdefgh");
  589.     check(memset(one+1, 'x', 3) == one+1, 1);    /* Return value. */
  590.     equal(one, "axxxefgh", 2);        /* Basic test. */
  591.  
  592.     /*void*/ memset(one+2, 'y', 0);
  593.     equal(one, "axxxefgh", 3);        /* Zero-length set. */
  594.  
  595.     /*void*/ memset(one+5, '\0', 1);
  596.     equal(one, "axxxe", 4);            /* Zero fill. */
  597.     equal(one+6, "gh", 5);            /* And the leftover. */
  598.  
  599.     /*void*/ memset(one+2, (char)010045, 1);
  600.     equal(one, "ax\045xe", 6);        /* Unsigned char convert. */
  601.  
  602.     printf("ending testprogramm without checking Berklix-functions\n");
  603.     printf("they not be exists in vbcc\n");
  604.     return;
  605.  
  606.     /*
  607.      * bcopy - much like memcpy
  608.      *
  609.      * Berklix manual is silent about overlap, so don't test it.
  610.      */
  611.     it = "bcopy";
  612.     /*void*/ bcopy("abc", one, 4);
  613.     equal(one, "abc", 1);            /* Simple copy. */
  614.  
  615.     /*void*/ strcpy(one, "abcdefgh");
  616.     /*void*/ bcopy("xyz", one+1, 2);
  617.     equal(one, "axydefgh", 2);        /* Basic test. */
  618.  
  619.     /*void*/ strcpy(one, "abc");
  620.     /*void*/ bcopy("xyz", one, 0);
  621.     equal(one, "abc", 3);            /* Zero-length copy. */
  622.  
  623.     /*void*/ strcpy(one, "hi there");
  624.     /*void*/ strcpy(two, "foo");
  625.     /*void*/ bcopy(one, two, 9);
  626.     equal(two, "hi there", 4);        /* Just paranoia. */
  627.     equal(one, "hi there", 5);        /* Stomped on source? */
  628.  
  629.     /*
  630.      * bzero
  631.      */
  632.     it = "bzero";
  633.     /*void*/ strcpy(one, "abcdef");
  634.     bzero(one+2, 2);
  635.     equal(one, "ab", 1);            /* Basic test. */
  636.     equal(one+3, "", 2);
  637.     equal(one+4, "ef", 3);
  638.  
  639.     /*void*/ strcpy(one, "abcdef");
  640.     bzero(one+2, 0);
  641.     equal(one, "abcdef", 4);        /* Zero-length copy. */
  642.  
  643.     /*
  644.      * bcmp - somewhat like memcmp
  645.      */
  646.     it = "bcmp";
  647.     check(bcmp("a", "a", 1) == 0, 1);    /* Identity. */
  648.     check(bcmp("abc", "abc", 3) == 0, 2);    /* Multicharacter. */
  649.     check(bcmp("abcd", "abce", 4) != 0, 3);    /* Honestly unequal. */
  650.     check(bcmp("abce", "abcd", 4) != 0, 4);
  651.     check(bcmp("alph", "beta", 4) != 0, 5);
  652.     check(bcmp("abce", "abcd", 3) == 0, 6);    /* Count limited. */
  653.     check(bcmp("abc", "def", 0) == 0, 8);    /* Zero count. */
  654.  
  655. }
  656.